package com.otitan.la.forest.system.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.otitan.la.forest.system.dto.LogDTO;
import com.otitan.la.forest.system.entity.LogEntity;
import com.otitan.la.forest.system.service.LogService;
import com.otitan.la.forest.system.vo.LogVO;
import com.otitan.webapp.framework.basepro.model.DataResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 日志表
 *
 * @author sunke
 * @email xxx
 * @date 2020-10-09 09:52:17
 */
@Slf4j
@Api(tags = "日志表API")
@RestController
@RequestMapping("/log")
public class LogController {

    @Autowired
    private LogService logService;


    @ApiOperation(value = "新增")
    @PostMapping
    public DataResult add(@Valid @RequestBody LogEntity log, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return DataResult.fail(bindingResult.getFieldError().getDefaultMessage());
        }
        return logService.add(log);
    }

//    @ApiOperation(value = "批量删除")
//    @DeleteMapping("/batchDelete")
//    public DataResult batchDelete(@RequestBody @ApiParam(value = "ID集合") List<String> ids) {
//        return logService.batchDelete(ids);
//    }
//    @ApiOperation(value = "删除")
//    @DeleteMapping("/delete/{id}")
//    public DataResult delete(@PathVariable("id") String id) {
//        List<String> ids = new ArrayList<String>() {{
//            add(id);
//        }};
//        return logService.batchDelete(ids);
//    }

//    @ApiOperation(value = "更新")
//    @PutMapping
//    public DataResult editor(@Valid @RequestBody LogEntity log, BindingResult bindingResult) {
//        return logService.editor(log, bindingResult);
//    }

    @ApiOperation(value = "列表查询（分页）")
    @PostMapping("/findPage/{page}/{size}")
    public DataResult<Page<LogVO>> findPageData(@PathVariable("page") long page,
                                                @PathVariable("size") long size,
                                                @RequestBody LogDTO log) {
        return logService.findPageData(page, size, log);
    }

//    @ApiOperation(value = "根据ID查询")
//    @GetMapping("/findOne/{id}")
//    public DataResult findOne(@PathVariable("id") String id) {
//        return logService.findOne(id);
//    }

}
